home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{5A65A9C0-089F-11D2-88AD-0000B45C4CF6}#1.2#0"; "EASYX.OCX"
- Begin VB.Form Form1
- Caption = "Animation Demo"
- ClientHeight = 2595
- ClientLeft = 165
- ClientTop = 450
- ClientWidth = 4680
- Icon = "Form1.frx":0000
- LinkTopic = "Form1"
- ScaleHeight = 173
- ScaleMode = 3 'Pixel
- ScaleWidth = 312
- StartUpPosition = 3 'Windows Default
- Begin PROJECTEXLibCtl.EasyX EasyX
- Left = 960
- OleObjectBlob = "Form1.frx":014A
- Top = 120
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Dim SurfaceOne As Long 'The sprite surface
- Dim SpriteArray(11) As Long 'The sprite array
- Dim X As Integer
- Dim Y As Integer
- Const ScreenWidth As Long = 800
- Const ScreenHeight As Long = 600
- Const MovePrLoop As Long = 10
- Const SpriteHeight As Long = 25
- Const SpriteWidth As Long = 25
- Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
- Private Declare Function GetTickCount Lib "kernel32" () As Long
- Private Sub SetUp()
- Dim rt As Long
- Dim AppPath As String
- Dim I As Integer, J As Integer
- AppPath = App.Path & "\"
- '....Always remember this....
- EasyX.Window = Me.hWnd '.
- '............................
- 'Initialize
- rt = EasyX.InitDirectDraw(ScreenWidth, ScreenHeight, 8)
- If rt <> EX_OK Then
- MsgBox "Direct draw initialization failed", vbOKOnly, "Direct draw failed"
- Exit Sub
- End If
- SurfaceOne = EasyX.LoadBitmapFile(AppPath & "balls.bmp", 0)
- 'The surface is the first surface to load so it must be 0
- 'See the documentation on loading bitmaps
- If SurfaceOne <> 0 Then
- EasyX.EndDirectX 'End the session
- 'Notify user
- MsgBox "The bitmap file could not be loaded", vbOKOnly, "Bitmap load failed"
- End If
- 'get the keyboard
- EasyX.InitDirectInput
- EasyX.CreateKeyboard
- EasyX.CreateKeyboard
- 'Fill the back (which will be the primary, when flipped) surface with black
- EasyX.FillSurface 0, EX_PRIMARYSURFACE
- 'Define the sprites of the newly created surface
- For I = 1 To 3
- For J = 1 To 4
- SpriteArray(((I - 1) * 3) + J - 1) = _
- EasyX.MakeSprite( _
- (J - 1) * SpriteWidth, _
- (I - 1) * SpriteHeight, _
- J * SpriteWidth, _
- I * SpriteHeight, SurfaceOne)
- Next J
- Next I
- X = 1
- Y = 1
- RunMain
- End Sub
- Private Sub Form_Load()
- SetUp
- End Sub
- Private Sub RunMain()
- Dim CurrentTick As Long
- Dim LastTick As Long
- Const TickDifference As Long = 5
- EasyX.AcquireKeyboard
- If EasyX.GetKeyState(EX_ESCAPE) = EX_KEYDOWN Then
- EasyX.EndDirectX
- Unload Me
- Exit Do
- End If
-
- CurrentTick = GetTickCount()
-
- If CurrentTick - LastTick > TickDifference Then
- LastTick = CurrentTick
- Update
- DoEvents
- Else
-
- DoEvents
- Sleep 1
-
- End If
-
-
- End Sub
- Private Sub Update()
- Static AnimationSeq As Integer
- Static PointX As Integer, PointY As Integer
-
-
- 'Update movement
- If PointX < 0 Or PointX > (ScreenWidth - SpriteWidth) Then
- X = X * -1
- End If
- If PointY < 0 Or PointY > (ScreenHeight - SpriteHeight) Then
- Y = Y * -1
- End If
- PointX = PointX + (X * MovePrLoop)
- PointY = PointY + (Y * MovePrLoop)
- 'Fill the surface with a given palette index
- EasyX.FillSurface 0, EX_PRIMARYSURFACE
- 'Draw the sprite
- EasyX.DrawSprite PointX, PointY, SpriteWidth, SpriteHeight, AnimationSeq
- EasyX.FlipSurface
- 'Update the sprite animation sequence
- AnimationSeq = AnimationSeq + 1
- 'reset the sequence if the variable is out of the array bound
- If AnimationSeq > UBound(SpriteArray) Then
- AnimationSeq = 0
- End If
- End Sub
-